package view.wizard;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.TextField;

public class Wiz2 extends WizardView {
	
	private TextField field = new TextField("Idade:", "", 2, TextField.DECIMAL);
	
	private Form form;
	
	private int age;
	
	protected void createView() {
		form = new Form("Passo 3");
		form.append(field);
	}

	public Displayable getScreen() {
		return form;
	}

	protected void initModel() {
		age = -1;
	}

	public int onEnter(int direction) {
		return OK;
	}

	public int onLeave(int direction) {
		if(direction==DIR_FORWARD) {
			String age_field = field.getString();
			if(age_field==null || age_field.length()==0) {
				return REJECT;
			}
			age = Integer.parseInt(age_field);
		}
		return OK;
	}

	protected void updateView() {
		if(age>0)
			field.setString(String.valueOf(age));
	}

	protected void viewCommandAction(Command cmd, Displayable display) {
		
	}

}